<template>
	<div class="hello">
		<h2>东软HIS</h2>
		<el-table :data="msg" style="width: 100%">
			<el-table-column prop="userName" label="登录名称" width="180">
			</el-table-column>
			<el-table-column prop="realName" label="真实姓名" width="180">
			</el-table-column>
			<el-table-column prop="password" label="用户密码" width="180">
			</el-table-column>
			<el-table-column label="操作">
				<template slot-scope="scope">
					<el-button @click="getIdClick(scope.$index, scope.row)">修改</el-button>
				</template>
			</el-table-column>
		</el-table>
		<!-- <el-button @click="submitClick">得到用户信息</el-button>-->
		<!-- <el-button type="text" @click="open">11</el-button> -->

		<el-dialog title="修改用户" :visible.sync="dialogFormVisible">
			<el-form :model="form">
				<el-form-item label="登录名:" :label-width="formLabelWidth">
					<el-input v-model="form.userName" autocomplete="off"></el-input>
				</el-form-item>
				<el-form-item label="密码:" :label-width="formLabelWidth">
					<el-input v-model="form.password" autocomplete="off"></el-input>
				</el-form-item>
				<el-form-item label="真实姓名:" :label-width="formLabelWidth">
					<el-input v-model="form.realName" autocomplete="off"></el-input>
				</el-form-item>
				<el-form-item label="所在科室" :label-width="formLabelWidth">
					<el-select v-model="form.deptId">
						<el-option v-for="item in typeDept" :key="index" :label="item.deptName" :value="item.id"></el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="用户类别" :label-width="formLabelWidth">
					<el-select v-model="form.useType">
						<el-option v-for="item in UseType" :key="index" :label="item.Use" :value="item.UseType" ></el-option>
						<!-- <el-option label="区域二" value="beijing"></el-option> -->
					</el-select>
				</el-form-item>
				<el-form-item label="医生职称" :label-width="formLabelWidth">
					<el-select v-model="form.docTitleId">
						<el-option v-for="item in typeDoc" :key="index" :label="item.constantName" :value="item.id"></el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="挂号级别" :label-width="formLabelWidth">
					<el-select v-model="form.registLeId">
						<el-option v-for="item in typeReg" :key="index" :label="item.registName" :value="item.id"></el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="是否参与排班:" :label-width="formLabelWidth">
					<el-radio v-model="form.isScheduling" label="是">是</el-radio>
					<el-radio v-model="form.isScheduling" label="否">否</el-radio>
				</el-form-item>
				<!-- <el-form-item label="活动区域" :label-width="formLabelWidth">
		      <el-select v-model="form.region" placeholder="请选择活动区域">
		        <el-option label="区域一" value="shanghai"></el-option>
		        <el-option label="区域二" value="beijing"></el-option>
		      </el-select>
		    </el-form-item> -->
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button @click="closeDialog">取 消</el-button>
				<el-button type="primary" @click="updateForm">确 定</el-button>
			</div>
		</el-dialog>
	</div>
</template>

<script>
	export default {
		name: 'HelloWorld',
		created() {
			this.initDic();
		},
		mounted: function() {
			this.submitClick();
			
		},
		data() {
			return {
				UseType:[],
				typeReg:[],
				typeDoc:[],
				typeDept: [],
				msg: [],
				dialogFormVisible: false,
				form: {},
				formLabelWidth: '250px'
			}
		},
		methods: {
			initDic() {
				this.$axios.get("/neusys/user/toadd")
					.then(response => {
						this.typeDept = response.data.deptList
						this.typeDoc = response.data.docList
						this.typeReg = response.data.regList
					})
					.catch();
			},
			submitClick() {
				this.$axios.get("/neusys/user/queryAllUser")
					.then(response => {
						this.msg = response.data;
						this.UseType = [{
							Use:'医院管理员',
							UseType:'1'
						},{
							Use:'挂号收费员',
							UseType:'2'
						},{
							Use:'门诊医生',
							UseType:'3'
						},{
							Use:'医技医生',
							UseType:'4'
						},{
							Use:'药房操作员',
							UseType:'5'
						},{
							Use:'财务管理员',
							UseType:'6'
						}]
					})
					.catch();
			},
			getIdClick(index, row) {
				this.$axios.get("/neusys/user/toupdate", {
						params: {
							id: this.msg[index].id,
						}
					})
					.then(response => {
						this.form = response.data
						this.dialogFormVisible = true
						// this.open(response.data);
					})
					.catch();
			},
			// open(data) {
			// 	this.$alert(data, '修改用户', {
			// 		dangerouslyUseHTMLString: true
			// 	});
			// },
			closeDialog() {
				this.form = {}
				this.dialogFormVisible = false
			},
			updateForm() {
				this.$confirm('你确定？？', '', {}).then(msg => {
					this.$axios.get("/neusys/user/newUpdate",{
						params:this.form
					})
						.then(response => {
							alert(response.data),
							this.closeDialog()
						})
						.catch();
				})
			}
		}
	}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
	h1,
	h2 {
		font-weight: normal;
	}

	ul {
		list-style-type: none;
		padding: 0;
	}

	li {
		display: inline-block;
		margin: 0 10px;
	}

	a {
		color: #42b983;
	}
</style>
